package com.fxpc.common.basedivision.service.Impl;

import com.fxpc.common.basedivision.service.BaseDivisionService;
import com.fxpc.hddc.activefault.dto.primary.entity.DivisionEntity;
import com.fxpc.hddc.activefault.jpa.dao.primary.BaseDivisionBaseDao;
import com.fxpc.hddc.activefault.jpa.dao.primary.EarthquakeDisivionRepository;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service

public class BaseDivisionServiceImpl implements BaseDivisionService {

    @Autowired
    EarthquakeDisivionRepository earthquakeDisivionRepository;

    private Logger logger = LoggerFactory.getLogger(getClass());

    /**
     * 获取省市县的所有信息
     *
     * @return
     */
//    @Override
//    public List<DivisionEntity> findAllDivison() {
//        return baseDivisionRepository.findAllDivison();
//    }

    /**
     * 查询数据库当前时间
     *
     * @return
     */
    @Override
    public LocalDateTime getTimeNow() {
        return earthquakeDisivionRepository.getTimeNow();
    }

    @Override
    public String getQhCode(String taskCode, String userName,int flag) {
        List<String> codes = earthquakeDisivionRepository.findCodeByTaskCodeAndName(taskCode, userName);
        String code="";
        if(codes.size()==1){
            code=(codes.get(0));
        }else{
            for (String str : codes) {
                if(flag==1 && str.length()==2){
                    code=str;
                }else if(flag==2 && str.length()==4){
                    code=str;
                }else if(flag==3 && str.length()==6){
                    code=str;
                }
            }
        }
        if(StringUtils.isEmpty(code)){
            System.out.println(code+"---------"+userName);
        }
        return code;
    }


}
